// pages/my/my.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myOptionsList:[{
      src:"/resources/my-image/my1.png",
      text:'我的资料',
      page:'profile',
      isShow: true,
      isUser: false,
    },{
      src:"/resources/my-image/my2.png",
      text:'健康管理师认证',
      page:'certification',
      isShow: true,
      isUser: false,
    },{
      src:"/resources/my-image/my3.png",
      text:'我的团队',
      page:'myTeam',
      isShow: false,
      isUser: false,
    },{
      src:"/resources/my-image/my5.png",
      text:'我的健康管理师',
      isShow: true,
      isUser: true,
    },{
      src:"/resources/my-image/my6.png",
      text:'分享招募',
      page: 'share',
      isShow: true,
      isUser: false,
    },{
      src:"/resources/my-image/my4.png",
      text:'我的设备',
      page: 'myDevice',
      isShow: true,
      isUser: false,
    }],
    isPic:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: app.globalData.userInfo
    })
    this.isCertification();
  },

  //是否认证
  isCertification: function(){
    var that = this
    wx.request({
      url: app.globalData.apiUrl + '/renz',
      data: {
        userId: app.globalData.userId,
      },
      method: 'get',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        // console.log(res)
        if(res.data.info){
          that.setData({
            userPic: res.data.info.userPic,
            nickName: res.data.info.nickName,
            isPic:true
          })
        }
        if(res.data.code == '200'){
          let index = 0
          for(var i in res.data.data){
            if(res.data.data[i].status == 2)
            {
              index++ 
            }
          }
          if(index > 0){
            that.navigatorIsShow();
          }
          that.setData({
            isCertification: 2,
            stateList: JSON.stringify(res.data.data)
          })
        }
        else if(res.data.code == '300')
        {
          that.setData({
            isCertification: 1
          })
        }
      },
      fail: function (res) {
        console.log("失败");
      }
    })
  },

  //我的团队是否显示
  navigatorIsShow:function(){
    var that = this;
    var arr = that.data.myOptionsList;
    for(var i in arr)
    {
      if(arr[i].text == "我的团队")
      {
        arr[i].isShow = true;
        break;
      }
    }
    that.setData({
      myOptionsList: arr
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow:function(){
    this.isCertification();
  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: 'PAPN小程序',
      path: 'pages/index/index?puid=' + app.globalData.userId,
      success: function(res) {
          res.shareTickets 
      },
      fail: function(res) {
          console.log(res)
      }
    }
  }
})